"""
新闻数据模型
"""
from datetime import datetime
from sqlalchemy import Column, Integer, String, DateTime, Text, Index
from modules.models.base import Base


class EconomicNews(Base):
    """经济新闻数据模型"""
    __tablename__ = "economic_news"
    
    id = Column(Integer, primary_key=True, autoincrement=True)
    title = Column(String(500), nullable=False, comment="新闻标题")
    content = Column(Text, nullable=True, comment="新闻内容")
    publish_time = Column(DateTime, nullable=False, index=True, comment="发布时间")
    source = Column(String(100), nullable=True, comment="新闻来源")
    category = Column(String(50), nullable=True, index=True, comment="新闻类别")
    url = Column(String(1000), nullable=True, comment="新闻链接")
    keywords = Column(String(500), nullable=True, comment="关键词")
    create_time = Column(DateTime, default=datetime.now, comment="创建时间")
    
    __table_args__ = (
        Index('idx_news_publish_time', 'publish_time'),
        Index('idx_news_source_category', 'source', 'category'),
    )
    
    def __repr__(self):
        return f"<EconomicNews(id={self.id}, title='{self.title[:30]}...', source='{self.source}')>"


class StockNotice(Base):
    """股票公告数据模型"""
    __tablename__ = "stock_notices"
    
    id = Column(Integer, primary_key=True, autoincrement=True)
    stock_code = Column(String(10), nullable=False, index=True, comment="股票代码")
    title = Column(String(500), nullable=False, comment="公告标题")
    content = Column(Text, nullable=True, comment="公告内容")
    publish_time = Column(DateTime, nullable=False, index=True, comment="发布时间")
    notice_type = Column(String(50), nullable=True, index=True, comment="公告类型")
    url = Column(String(1000), nullable=True, comment="公告链接")
    create_time = Column(DateTime, default=datetime.now, comment="创建时间")
    
    __table_args__ = (
        Index('idx_notice_stock_time', 'stock_code', 'publish_time'),
    )
    
    def __repr__(self):
        return f"<StockNotice(stock_code='{self.stock_code}', title='{self.title[:30]}...', publish_time='{self.publish_time}')>"